﻿// DOMContentLoaded
$(function () {

    // bind radiobuttons in the form
    var $filterType = $('#filter input[name="type"]');
    var $filterYear = $('#filter input[name="year"]');

    // get the first collection
    var $applications = $('div#detailtable');

    // clone applications to get a second collection
    var $data = $applications.clone();

    // attempt to call Quicksand on every form change
    $('#filter input').change(function (e) {        

        var $selecttype = $('#filter input[name="type"]:checked').val();
        var $selectyear = $('#filter input[name="year"]:checked').val();

        $data.each(function (i) {
            $(this).find('li').removeClass('gallerybox');
            if ($selecttype == 'all' && $selectyear == 'all') {
                var $filteredData = $(this).find('li');
            }
            else if ($selecttype == 'all' && $selectyear != 'all') {
                var $filteredData = $(this).find('li[data-year="' + $selectyear + '"]');
            }
            else if ($selecttype != 'all' && $selectyear == 'all') {
                var $filteredData = $(this).find('li[data-type="' + $selecttype + '"]');
            } else {
                var $filteredData = $(this).find('li[data-type="' + $selecttype + '"][data-year="' + $selectyear + '"]');
            }

            // finally, call quicksand
            $applications.eq(i).quicksand($sortedData, {
                duration: 800,
                easing: 'easeInOutQuad'
            });
        });


    });

});